package com.sinping.qh.service.base;

import com.sinping.qh.domain.user.UserLaboratory;
import com.sinping.qh.repository.mongo.user.UserLaboratoryRepository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangjin
 * @create 2018/8/2
 */
public class BaseService {



    public List<String> getUnitIDLists(UserLaboratoryRepository userLaboratoryRepository,
                             String userId)    {
        //已经配置实验室的院系，在院系配置中要删除
        List<String> handleUnitIDLists = new ArrayList<>();
        //查询所负责实验室
        List<String> labIDLists = new ArrayList<>();
        List<UserLaboratory> labList = userLaboratoryRepository.findAllByUserIdAndTypeOrderByGmtCreatedDesc(userId, "1");
        if (null!=labList && labList.size() > 0) {
            for (int i = 0; i < labList.size(); i++) {
                labIDLists.add(labList.get(i).getManagerLabId());
                handleUnitIDLists.add(labList.get(i).getManagerUnitId());
            }
        }
        //查询所负责院系
        List<String> unitIDLists = new ArrayList<>();
        List<UserLaboratory> unitList = userLaboratoryRepository.findAllByUserIdAndTypeOrderByGmtCreatedDesc(userId, "0");
        if (null!=unitList && unitList.size() > 0) {
            for (int i = 0; i < unitList.size(); i++) {
                //两个集合去重复
                if (null!=handleUnitIDLists && handleUnitIDLists.size() > 0) {
                    if (!handleUnitIDLists.contains(unitList.get(i).getManagerUnitId())) {
                        unitIDLists.add(unitList.get(i).getManagerUnitId());
                    }
                } else {
                    unitIDLists.add(unitList.get(i).getManagerUnitId());
                }

            }
        }
        return unitIDLists;
    }

    public List<String> getLabIDLists(UserLaboratoryRepository userLaboratoryRepository,
                                       String userId)    {
        //查询所负责实验室
        List<String> labIDLists = new ArrayList<>();
        List<UserLaboratory> labList = userLaboratoryRepository.findAllByUserIdAndTypeOrderByGmtCreatedDesc(userId, "1");
        if (null!=labList && labList.size() > 0) {
            for (int i = 0; i < labList.size(); i++) {
                labIDLists.add(labList.get(i).getManagerLabId());
               }
        }

        return labIDLists;
    }
}
